﻿<html>
  <head>
    <title></title>
    <div id="themefile"></div>
    <style>
      @import 'this://app/images/public.css';
      @import 'images/form.css';
      html {
        background: color(center-background-color);
      }
      body {
        width: *;
        height: max-content;
        overflow: hidden;
        margin: 0;
        padding: 0;
        font-size: 12dip;
        color: color(general-text-color);
      }
      input {
        width: 300dip;

      }
      .input_wrapper {
        padding: 0 10dip 10dip 10dip;
        flow: row(label, input);
      }
      table td {
        vertical-align: middle;
        padding-bottom: 5dip;
      }
      table td:first-child {
        width: 100dip;
      }
    </style>
  </head>
  <body>
    <div class="input_wrapper">
      <table>
        <tr><td>{{FilePath}}：</td><td><input type="text" id="name" value="" readonly></td></tr>
        <tr>
          <td>
            <div class="tip" title="{{RomSimParamsDesc}}">?</div>
            {{SimParams}}：
          </td>
          <td><input type="text" id="cmd" value="" novalue="{{SimParams}}" /></td>
        </tr>
        <tr>
          <td>
            <div class="tip" title="{{LuaDesc}}">?</div>
            {{Lua}}：
          </td>
          <td>
            <input type="text" id="sim_lua" value="" />
            <button
              class="openfile"
              for="sim_lua"
              id="lang_SelectBootFile"
              caption="{{SelectBootFile}}"
              filter="lua Files (*.lua)|*.lua|All Files (*.*)|*.*"
            >
              ...
            </button>
          </td>
        </tr>
        <tr>
          <td>
            <div class="tip" title="{{UnzipRunDesc}}">?</div>
            {{UnzipRun}}：
          </td>
          <td>
            <select id="unzip">
              <option value="0">{{UnzipDefault}}</option>
              <option value="2">{{No}}</option>
              <option value="1">{{Yes}}</option>
            </select>
          </td>
        </tr>
        <tr>
          <td>
            <div class="tip" title="{{RomCmdFileTip}}">?</div>
            {{RomCmdFile}}：
          </td>
          <td><input type="text" id="file" value="" /></td>
        </tr>
      </table>
    </div>
    <div class="form_bottom">
      <button class="cancel" id="close-dialog">{{Cancel}}</button>
      <button class="ok" id="ok" role="default-button">{{OK}}</button>
    </div>
    <script type="text/tiscript">

      include ROOTPATH + "js/utils.js";

      //初始化主题
      initUiTheme();

      //创建语言
      createLang();

      view.root.on("ready", function(){

          var romId = view.parameters.romId;
          var simId = view.parameters.simId;
          var cmd = JSON.parse(mainView.GetRomCmd(romId,simId));
          var sim = JSON.parse(mainView.GetSimulatorById(simId));
      
          $(#name).value = sim.Path;
          $(#cmd).value = cmd.Cmd;
          $(#unzip).value = cmd.Unzip;
          $(#file).value = cmd.File;
          $(#sim_lua).value = cmd.Lua;

          view.windowCaption =  sim.Name;
      });

      //保存修改
      event click $(#ok){
          var data = {
              cmd:$(#cmd).value,
              unzip:$(#unzip).value.toString(),
              file:$(#file).value.toString(),
              lua:$(#sim_lua).value.toString(),
          }
          var datastr = JSON.stringify(data);
          
          var romId = view.parameters.romId;
          var simId = view.parameters.simId;

          mainView.UpdateRomCmd(romId,simId,datastr);
          view.close();
      }

      //关闭
      event click $(#close-dialog){
          view.close();
      }

      //选择文件
      event click $(.openfile){
          openFile(this);
      }

      //选择文件
      function openFile(evt){
          const defaultExt = "";
          const initialPath = "";
          const filter = evt.attributes["filter"];
          const caption = evt.attributes["caption"];
          var url = view.selectFile(#open, filter, defaultExt, initialPath, caption );
          var out = self.select("#"+evt.attributes["for"]);
          if(url){
              url = URL.toPath(url);
              url = url.split("\/").join(SEPARATOR);
              url = url.split(CONF.RootPath.toString()).join("");
              out.value = url;
          }
      }
    </script>
  </body>
</html>
